package dataserver.mapper;

import dataserver.pojo.SceneDeviceRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface SceneDeviceRelationRepository extends JpaRepository<SceneDeviceRelation, Integer>, JpaSpecificationExecutor<SceneDeviceRelation> {
    /**
     * 查询根据设备ID
     */
    @Query(value = "select data from SceneDeviceRelation data where data.unrealName in (:unrealName)")
    List<SceneDeviceRelation> findByUnrealName(@Param("unrealName") List<String> unrealName);

    /**
     * 查询根据站场ID
     */
    @Query(value = "select data from SceneDeviceRelation data where " +
            " data.stationId = :stationId " +
            " and data.unrealName = :unrealName " +
            " and data.type = :type " +
            " and data.equipmentId = :equipmentId")
    List<SceneDeviceRelation> findData(@Param("stationId") String stationId,
                                 @Param("unrealName") String unrealName,
                                 @Param("type") String type,
                                 @Param("equipmentId") String equipmentId);
}